import torch
from utils.models import LeapGestureClassifier
from utils.transform import transform
from utils.dataset import LeapGestRecogData
from torch.utils.data import DataLoader

def infer():
    # 加载整个模型
    model = torch.load('models/leap_gesture_model_full.pth')
    model.eval()

    # 创建数据加载器
    dataset = LeapGestRecogData("data/leapGestRecog", transform)
    dataloader = DataLoader(dataset, batch_size=16, shuffle=False)

    # 进行预测
    correct = 0
    total = 0
    with torch.no_grad():
        for inputs, labels in dataloader:
            outputs = model(inputs)
            _, predicted = torch.max(outputs, 1)
            total += labels.size(0)
            correct += (predicted == labels).sum().item()

    acc = 100.0 * correct / total
    print(f'Inference Accuracy: {acc:.2f}%')

if __name__ == "__main__":
    infer()